#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

const int N = 1e5 + 10;

ll dep[N];
int n, dfn[N], R[N], tot, m, stu[N], pot[N << 1];
veg G[N];
ll ans;
set < int > s;

namespace T {
	const int N = 2e5 + 10;
	const int K = 18;
	int f[K + 1][N], lg[N];
	inline int tmin(const int &x, const int &y) { return dep[x] < dep[y] ? x : y; }
	void dfs(int x, int p) {
		pot[dfn[x] = R[x] = ++tot] = x;
		for(auto y : G[x]) if(y.fi ^ p) dep[y.fi] = dep[x] + y.se, dfs(y.fi, x), pot[R[x] = ++tot] = x;
	}
	void init() {
		rep(i, 1, tot) f[0][i] = pot[i];
		rep(i, 1, K)
			rep(j, 1, tot) f[i][j] = tmin(f[i - 1][j], f[i - 1][j + (1 << (i - 1))]);
		rep(i, 2, tot) lg[i] = lg[i >> 1] + 1;
	}
	int lca(int x, int y) {
		if(dfn[x] > dfn[y]) swap(x, y);
		x = dfn[x]; y = R[y]; int k = lg[y - x + 1];
		return tmin(f[k][x], f[k][y - (1 << k) + 1]);
	}
	ll dis(int x, int y) { return dep[x] + dep[y] - 2 * dep[lca(x, y)]; }
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, m = in; rep(i, 2, n) { int x = in, y = in, z = in; G[x].eb(y, z); G[y].eb(x, z); }
	T :: dfs(1, 0); T :: init();
	while(m--) {
		int x = in;
		if(!stu[x]) s.ep(dfn[x]);
		auto it = s.find(dfn[x]);
		int y = pot[it == s.begin() ? *s.rbegin() : *prev(it)], z = pot[it == --s.end() ? *s.begin() : *next(it)];
		ll delta = T :: dis(y, x) + T :: dis(x, z) - T :: dis(y, z);
		if(!stu[x]) ans += delta; else ans -= delta, s.erase(dfn[x]);
		stu[x] ^= 1;
		printf("%lld\n", ans);
	}
	return 0;
}
